package github.kawaiior.yuanchuxiuzhen.common.item.misc;

import github.kawaiior.yuanchuxiuzhen.core.init.itemgroup.YcxzGroup;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;

import java.util.Random;

public class ManaStoneBag extends Item {
    public ManaStoneBag() {
        super(new Properties().group(YcxzGroup.YCXZ_GROUP).maxStackSize(16));
    }

    public static int getLevel() {
        int value = random.nextInt(100);
        if (value < 90) {
            return random.nextInt(6) + 1;
        } else if (value < 98) {
            return random.nextInt(2) + 7;
        } else {
            return 9;
        }
    }

    public static int getCount(){
        return random.nextInt(5) + 1;
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        if (!worldIn.isRemote){
            ItemStack itemstack = playerIn.getHeldItem(handIn);
            if (itemstack.getItem() instanceof ManaStoneBag){
                playerIn.addItemStackToInventory(new ItemStack(ManaStoneItem.getManaStone(getLevel()), getCount()));
                itemstack.shrink(1);
            }
        }
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

}
